package com.gsafety.libraryktx.widget

import android.content.Context
import android.text.Html
import android.widget.TextView
import com.github.mikephil.charting.components.MarkerView
import com.github.mikephil.charting.data.CandleEntry
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.highlight.Highlight
import com.github.mikephil.charting.utils.MPPointF
import com.github.mikephil.charting.utils.Utils
import com.gsafety.libraryktx.R


class LineChartMarkView : MarkerView {


    constructor(context: Context) : super(context, R.layout.common_line_chart_mark_layout) {
    }

    override fun refreshContent(e: Entry?, highlight: Highlight?) {
        if (e is CandleEntry) {
            setTextContent(Utils.formatNumber(e.high, 0, true))
        } else {
            setTextContent(Utils.formatNumber(e!!.y, 0, true))
        }

        super.refreshContent(e, highlight)
    }

    override fun getOffset(): MPPointF {
        return MPPointF((-(width / 2)).toFloat(), (-height).toFloat())
    }


    fun setTextContent(content: String) {
        var tvContent = findViewById<TextView>(R.id.line_chart_mark_tv_content)
        tvContent.text = Html.fromHtml(content)
    }
}